package com.seu.project.seuquiz.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 使用下面两个注解，就会自动注入同名属性
@Configuration
@ConfigurationProperties(prefix = "spring.redis")       // 读取配置文件中spring.redis前缀
@Data
public class RedissonConfig {

    private Integer database;

    private String host;

    private Integer port;

    private String password;


    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setDatabase(database)     // 之后考虑限流数据库和业务数据库分开
                .setAddress("redis://" + host +  ":" + port);
//                .setPassword();
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
